module namespace fonesfilter = "http://fones.com/filter";
declare namespace rest = "http://exquery.org/ns/restxq";
declare namespace owl = "http://www.w3.org/2002/07/owl#";
import module namespace fones = "http://fones.com" at "file:///A:/Applications/BaseX/http/modifiedfoneshome.xqm" ;
(: The current location should be replaced by the actual location of the module in the server :)

declare variable $fonesfilter:ontologies := db:open("OWLDB")//owl:Ontology;

declare %output:media-type("text/html")
     %rest:query-param("filterKey", "{$filterKey}")
     %rest:query-param("filterCondition", "{$condition}")
     %rest:query-param("filterValue", "{$value}")
     %rest:path("modifiedfones/filter/") 
     %rest:GET
     function fonesfilter:filterRequest($filterKey as xs:string,$condition as xs:string ,$value as xs:integer){
       fonesfilter:filterOntologies($filterKey,$condition ,$value)
     };
declare function fonesfilter:filterOntologies($filterKey as xs:string,$condition as xs:string ,$value as xs:integer){
   <html>
 		<head>
       <title>Ontology Repository</title>
			</head>
			<body>
				<h2>Ontology Repository</h2>
	  		<h3>Ontologies</h3>
				<table>
			   <tr>
			    <th>Ontology</th>
			   </tr>
			   { for $ont in $fonesfilter:ontologies
    	  	return 
          <tr> 
           <td>
            {
            if( lower-case($filterKey) = "logical axioms") then let $count:=fones:logicalAxiomCount($ont) return 
              if($condition =">") 
                  then if($count > $value) 
                        then fn:replace(fones:substring-after-last-match($ont//@ontologyIRI, '/'),'#',' ')
                  else()	
		          else              
                  if($count <$value)
                       then fn:replace(fones:substring-after-last-match($ont//@ontologyIRI, '/'),'#',' ') 
                  else()
					  else()
					  }
           </td>
			     </tr>
           }
  			</table>
				</body>
			</html>
};
